package com.gcxy.controller;


import com.gcxy.core.R;
import com.gcxy.dto.resources.AddResourceDTO;
import com.gcxy.dto.resources.ResourcePageDTO;
import com.gcxy.dto.resources.UpdateResourceDTO;
import com.gcxy.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pep7chiao
 * @since 2022-09-27
 */
@RestController
@Api(tags = "资源管理")
@RequestMapping("/resource")
public class ResourceController {
    @Resource
    private ResourceService resourceService;

    @ApiOperation("获取所有资源权限")
    @GetMapping("/getResourceList")
    public R getResourceList() {
        return R.Success(resourceService.getResourceList());
    }

    @ApiOperation("根据角色ID获取资源权限")
    @GetMapping("/getResourceByRoleId/{roleId}")
    public R getResourceByRoleId(@PathVariable Integer roleId) {
        return  R.Success(resourceService.getResourceByRoleId(roleId));
    }

    @ApiOperation("根据条件查询资源")
    @GetMapping("/getResourceByCondition")
    public R getResourceByCondition(@Validated ResourcePageDTO resourcePageDTO) {
        return R.Success(resourceService.getResourceByCondition(resourcePageDTO));
    }

    @ApiOperation("更新资源")
    @PutMapping("/updateRole")
    public R<?> updateRole(@Validated @RequestBody UpdateResourceDTO updateResourceDTO) {
        return resourceService.UpdateResource(updateResourceDTO);
    }

    @ApiOperation("新增资源")
    @PostMapping("/insertResource")
    public R<Void> insertResource(@Validated @RequestBody AddResourceDTO addResourceDTO) {
        return resourceService.insertResource(addResourceDTO);
    }

    @ApiOperation("删除资源")
    @DeleteMapping("/deleteResource/{id}")
    public R<?> deleteResourceById(@PathVariable Integer id) {
        return resourceService.deleteResourceById(id);
    }

}
